<?php

if (! defined('SIMPLE_TEST')) {
    define('SIMPLE_TEST', '../simpletest/');
}
require_once(SIMPLE_TEST . 'autorun.php');

require_once '../Sql/DBAluminioDAO.php';
require_once '../Sql/conexion.php';
require_once '../Sql/claseDB.php';
require_once '../Exception/CustomException.php';
require_once '../Class/Aluminio.php';


class DBAluminioDAOTest extends UnitTestCase {

    function DBAluminioDAOTest() {
        $this->UnitTestCase();
    }

    public function testgetPrecio() {
        $DBAluminioDAOTest = new DBAluminioDAO();
        $DBConn = null;
        $conexion = new conexion();
        $DBConn = $conexion->setConnect();
        $DBConn->consulta( "INSERT INTO costo_aluminio
                            VALUES (-1,'Prueba Aluminio',
                            'Tipo accesorio prueba',10,20,
                            30,40,1)" );
        
        $PrecioColor1 = $DBAluminioDAOTest->getPrecio(-1,1);
        $PrecioColor2 = $DBAluminioDAOTest->getPrecio(-1,2);
        $PrecioColor3 = $DBAluminioDAOTest->getPrecio(-1,3);
        $PrecioColor4 = $DBAluminioDAOTest->getPrecio(-1,4);
        $this->assertEqual($PrecioColor1, 10);
        $this->assertEqual($PrecioColor2, 20);
        $this->assertEqual($PrecioColor3, 30);
        $this->assertEqual($PrecioColor4, 40);
        $DBConn->consulta("DELETE FROM costo_aluminio
                          WHERE CAL_ID = -1" );
    }

    public function testgetNombre() {
        $DBAluminioDAOTest = new DBAluminioDAO();
        $DBConn = null;
        $conexion = new conexion();
        $DBConn = $conexion->setConnect();
        $DBConn->consulta( "INSERT INTO costo_aluminio
                            VALUES (-1,'Prueba Aluminio',
                            'Tipo accesorio prueba',10,20,
                            30,40,1)" );

        $Nombre = $DBAluminioDAOTest->getNombre( -1 );
        $this->assertEqual( $Nombre, 'Prueba Aluminio' );
        $DBConn->consulta("DELETE FROM costo_aluminio
                          WHERE CAL_ID = -1" );
    }

    public function testgetTipo() {
        $DBAluminioDAOTest = new DBAluminioDAO();
        $DBConn = null;
        $conexion = new conexion();
        $DBConn = $conexion->setConnect();
        $DBConn->consulta( "INSERT INTO costo_aluminio
                            VALUES (-1,'Prueba Aluminio',
                            'Tipo accesorio prueba',10,20,
                            30,40,1)" );

        $Tipo = $DBAluminioDAOTest->getTipo( -1 );
        $this->assertEqual( $Tipo, 'Tipo accesorio prueba' );
        $DBConn->consulta("DELETE FROM costo_aluminio
                          WHERE CAL_ID = -1" );
    }

    public function testsetAluminio() {
        $DBAluminioDAOTest = new DBAluminioDAO();
        $miAluminio = new Aluminio( 'Prueba Aluminio', 'Tipo accesorio prueba',
                                    'Prueba Color', 'Prueba tipo', 10, 20, 30);
        $DBConn = null;
        $conexion = new conexion();
        $DBConn = $conexion->setConnect();
        $DBConn->consulta( "INSERT INTO presupuesto
                           VALUES (-1, 'PRESUPUESTO',
                           '2010-06-04', NULL, NULL,
                           NULL, 1, 1)" );


        $DBAluminioDAOTest->setAluminio( $miAluminio, -1 );
        $DBConn->consulta( "SELECT * FROM Aluminio
                        WHERE ALM_NOMBRE = 'Prueba Aluminio'
                        AND ALM_TIPO = 'Tipo accesorio prueba'
                        AND ALM_COLOR = 'Prueba Color'
                        AND ALM_TIPO_COLOR = 'Prueba tipo'
                        AND ALM_ANCHO = 10
                        AND ALM_PRECIO = 20
                        AND ALM_CANTIDAD = 30
                        AND ALM_STATUS = 1
                        ORDER BY ALM_ID DESC " );

        $fila = $DBConn->extraer_registro();
        $id = $fila['ALM_ID'];
        $this->assertEqual( $fila['ALM_NOMBRE'], 'Prueba Aluminio' );
        $this->assertEqual( $fila['ALM_TIPO'], 'Tipo accesorio prueba' );
        $this->assertEqual( $fila['ALM_COLOR'], 'Prueba Color' );
        $this->assertEqual( $fila['ALM_TIPO_COLOR'], 'Prueba tipo' );
        $this->assertEqual( $fila['ALM_ANCHO'], 10 );
        $this->assertEqual( $fila['ALM_PRECIO'], 20 );
        $this->assertEqual( $fila['ALM_CANTIDAD'], 30 );

        $DBConn->consulta( "SELECT *
                            FROM detalle_presupuesto
                            WHERE DPR_PTO_ID = -1" );

        $fila = $DBConn->extraer_registro();
        $this->assertEqual( $fila['DPR_PTO_ID'], -1 );
        $this->assertEqual( $fila['DPR_ALM_ID'], $id );
        $DBConn->consulta( "DELETE FROM detalle_presupuesto
                            WHERE DPR_ALM_ID = $id
                            AND DPR_PTO_ID = -1" );

        $DBConn->consulta( "DELETE FROM presupuesto
                            WHERE PTO_ID = -1" );

        $DBConn->consulta( "DELETE FROM aluminio
                            WHERE ALM_ID = $id" );


    }
}
?>
